package edu.nf.relaxenjoy.web.controller.app;

import com.github.pagehelper.PageInfo;
import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.common.validator.ValidatorUtils;
import edu.nf.relaxenjoy.common.validator.group.DefaultGroup;
import edu.nf.relaxenjoy.domain.dto.TagDTO;
import edu.nf.relaxenjoy.domain.entity.Tag;
import edu.nf.relaxenjoy.domain.vo.PostVo;
import edu.nf.relaxenjoy.domain.vo.TagVo;
import edu.nf.relaxenjoy.service.TagService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhu
 * @date 2024-12-20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/tag")
@Api(tags="标签模块")
public class TagController extends BaseController {

    private final TagService tagService;

    /**
     * 获取所有标签
     *
     * @return
     */
    @RequestMapping("getAllTag")
    public ResultVO getAllTag() {
        List<TagVo> voList = tagService.getAllTag();
        return success(voList);
    }

    /**
     * 得到当前标签信息
     *
     * @param id
     * @return
     */
    @RequestMapping("getOneTag")
    public ResultVO getOneTag(String id) {
        Tag tag = tagService.getById(Long.parseLong(id));
        return success(tag);
    }

    /**
     * 根据标签id获取图片信息
     *
     * @param id
     * @param type
     * @return
     */
    @RequestMapping("getImgListByTagId/{page}/{limit}")
    public ResultVO getImgListByTag(@PathVariable long page, @PathVariable long limit, String id, Integer type) {
        PageInfo<PostVo> postVoList = tagService.getImgListByTag(page, limit, id, type);
        return success(postVoList);
    }

    /**
     * 添加标签
     *
     * @param tagDTO
     * @return
     */
    @RequestMapping("saveTag")
    public ResultVO saveTag(@RequestBody TagDTO tagDTO) {
        ValidatorUtils.validateEntity(tagDTO, DefaultGroup.class);
        Tag tag = tagService.saveTag(tagDTO);
        return success(tag);
    }

}
